<template>
    <div >
        <h2 style="text-align: center;">线下挂号</h2>
        <center>
        <el-form :inline="true" style="margin: 40px 0;width: 80%;" ref="ADDForm" :model="patientInfo" :rules="rules" class="demo-form-inline">
            <el-form-item label="姓名" prop="name">
                <el-input v-model="patientInfo.name" placeholder="请输入姓名"></el-input>
            </el-form-item>

            <el-form-item label="身份证"  style="margin-left: 50px" prop="idCard">
                <el-input v-model="patientInfo.idCard" placeholder="请输入身份证"></el-input>
            </el-form-item>
            <br>
            <el-form-item label="电话" prop="phone">
                <el-input v-model="patientInfo.phone" placeholder="请输入电话"></el-input>
            </el-form-item>
            <el-form-item label="地址" style="margin-left: 64px" prop="address">
                <el-input v-model="patientInfo.address" placeholder="请输入地址"></el-input>
            </el-form-item>
            <br>
            <center>
                <el-form-item >
                <el-button type="primary" @click="onSubmit('ADDForm')">挂号</el-button>
            </el-form-item>
            </center>
        </el-form>
        </center>
    </div>
</template>

<script>
    import axios from "axios";
    import {ElMessage} from "element-plus";

    export default {
        name: "GetQueue",
        data() {
            return {
                patientInfo:{
                    address: "",
                    age: 0,
                    deleted: 0,
                    gmtCreate: "",
                    gmtUpdate: "",
                    id: "",
                    idcard: "",
                    loginName: "",
                    name: "",
                    password: "123",
                    phone: "",
                    sex: 0
                },
                rules:{
                    name:[
                        {required:true,message:"姓名不可为空",trigger:'blur'}
                    ],
                    career:[
                        {required:true,message:"资历不可为空",trigger:'blur'}
                    ],
                    level:[
                        {required:true,message:"水平不可为空",trigger:'blur'}
                    ],
                    info:[
                        {required:true,message:"简介不可为空",trigger:'blur'}
                    ],
                    sex:[
                        {required:true,message:"性别不可为空",trigger:'blur'}
                    ],
                    age:[
                        {required:true,message:"年龄不可为空",trigger:'blur'}
                    ],
                    idCard: [
                        {required:true,message:"身份证不可为空",trigger:'blur'},
                        { min: 18, max: 18, message: '请正确输入身份证号', trigger: 'blur' },
                    ],
                    phone:[
                        {required:true,message:"电话不可为空",trigger:'blur'},
                        { min: 11, max: 11, message: '请正确输入电话号码', trigger: 'blur' },
                    ],
                    login_name:[
                        {required:true,message:"登录昵称不可为空",trigger:'blur'}
                    ],
                    address:[
                        {required:true,message:"地址不可为空",trigger:'blur'}
                    ],

                },
            }
        },
        methods: {
            onSubmit(formName) {
                this.$refs[formName].validate((valid)=>{
                    if(valid){
                        axios.post("http://119.29.60.153:8001/doctorservice/registration/addPatientByReception",this.patientInfo).then(resp=> {
                            if(resp.data.success===true){
                                this.patientInfo={};
                                localStorage.setItem('pid',resp.data.data.id)
                                this.$router.push({name:'RChooseDepartment',})
                            }else {
                                ElMessage.error('挂号失败')
                            }

                        });
                    }else {
                        return false;
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>